<%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<div style="width: 500px; height: 250px;">
	<div class="tree-panel" style="width: 245px;height: 250px;overflow: auto;">
		<ul id="common_ztree_list" class="ztree"></ul>
	</div>
	<div class="trigger close" onclick="$('.tree-panel',$.cssTab.focus()).toggle();$(this).toggleClass('close');"></div>
	<div style="float:left;width: 245px;height: 250px;overflow: auto;">
		<ul id="orglist">
		</ul>
	</div>
</div>
<div class="set-btn" data-spy="affix" data-offset-top="200">
	<button class="btn green" id="save" type="button">确定</button>
	<a class="btn" href="javascript:;" onclick="closeDialog()">取消</a>
</div>
<script type="text/javascript" src="acl/common/tree/js/ztree.js"></script>
<script>
	function orglist_addli(zTree,node){
		var jshtml = '<li id="' +node.tId+ '">';
			jshtml += '<a href="javascript:delChecked(\'' +zTree+ '\',\'' +node.tId+ '\',orglist_delli)" title="删除"><img style="margin-bottom:-3px" src="portal/images/icon/btn_del.png" alt="删除" /></a> &nbsp;' ;
			jshtml += '<span style="cursor:pointer;" onclick="javascript:expandNode(\''+zTree+'\',\''+node.id+'\')" title="' +getNodePath(node)+ '">' +node.name+ '</span> &nbsp;';
			jshtml += '</li>';
		$('#orglist',$css.focusDialog()).append(jshtml);
	}
	function orglist_reload(zTree){
		var nodes = [];
			var data = $.dialog.focus.data;
			if(data.settings.getCheckedNodes){
				nodes =data.settings.getCheckedNodes(zTree);
			}else{
				nodes = getCheckedNodes(zTree);
			}
		$('#orglist',$css.focusDialog()).html('');
		for(var i=0;i<nodes.length;i++){
			node = nodes[i];
			orglist_addli(zTree,node);
		}
	}
	function orglist_delli(zTree,tId){
		$('#orglist>li#'+tId,$css.focusDialog()).remove();
	}
	function closeDialog(){
		$.fn.zTree.destroy('common_ztree_list');
		$css.closeDialog();
	}
	$(function(){
		using('tree',function(){
			var data = $.dialog.focus.data;
			var settings = data.settings;
			function zTreeOnCheck(event, treeId, treeNode) {
			    if(treeNode){
					//orglist_addli('common_ztree_list',treeNode);
					orglist_reload(treeId);
				}
			}
			function onAsyncSuccess(event, treeId, treeNode) {
			    orglist_reload(treeId);
			}
			var setting = settings.setting;
			if(!setting.callback)setting.callback={};
			setting.callback.onCheck=zTreeOnCheck;
			setting.callback.onAsyncSuccess=onAsyncSuccess;
			$($("#common_ztree_list"),$css.focusDialog()).OrgTree(settings);   
		});
		setTimeout(function(){
			
		},10);
		$('#save',$css.focusDialog()).click(function(){
			var nodes = {};
			var data = $.dialog.focus.data;
			if(data.settings.getCheckedNodes){
				nodes = data.settings.getCheckedNodes('common_ztree_list');
			}else{
				nodes = getCheckedNodes('common_ztree_list');
			}
			if(data.save(nodes)){
				closeDialog();
			}
		});
	})
</script>